<style>
.product_img img {
	border: solid 3px #fff;
	margin-right: 5px;
}
.product_img img.hover {
	border-color: #ff8800;
}
.product_img img.current {
	border-color: #df0001;
}
</style>
<div class="container bm-page">
  <div class="col-md-8">
    <div class="bm-form-container" >
      <div class="pay-crumbs-box">
        <div class="pay-crumbs"></div>
      </div>
      <div class="form-box">
        <div class="head"> <i class="bm-spt"></i> <span>请填写</Span>报名信息 </div>
        <div></div>
        <form id="goodsbm" action="<?php echo YzwController::U('bmedit') ?>" method="post">
          <table class="form">
            <tbody>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'detail_url'); ?>：</td>
                <td><input type="text" name="detail_url" class="input input-mid" value="<?php echo $data->detail_url ?>" id="detail_url" placeholder="请填写商品地址，支持淘宝、天猫、京东" disabled>
                  <input type="button" class="get-good bm-spt" id="get_good"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'goods_name'); ?>：</td>
                <td><input type="text" class="input input-big" name="goods_name" id="goods_name" maxlength="15" value="<?php echo $data->goods_name ?>" placeholder="标题最短不能少于7个，最长不能大于10个"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'product_id'); ?>：</td>
                <td><input type="text" class="input input-big" id="product_id" disabled="disabled" value="<?php echo $data->product_id ?>">
                  <input type="hidden" class="input input-big" name="product_id" value="<?php echo $data->product_id ?>"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'cat_id'); ?>：</td>
                <td><select name="cat_id">
                    <option value="">请选择商品分类</option>
                    <?php echo CategoryModel::model()->htmlCategorySelectOption($data->cat_id) ?>
                  </select></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'p_price'); ?>：</td>
                <td><input type="text" class="input input-sm" id="p_price" disabled="disabled" value="<?php echo $data->p_price ?>">
                  宝贝原价由系统自动获取，报名时不能修改宝贝原价
                  <input type="hidden" class="input input-sm" name="p_price" value="<?php echo $data->p_price ?>"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'promo_price'); ?>：</td>
                <td><input type="text" class="input input-sm" name="promo_price" id="promo_price" value="<?php echo $data->promo_price ?>"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'sales'); ?>：</td>
                <td><input type="text" class="input input-sm" name="sales" id="sales" value="<?php echo $data->sales ?>"></td>
              </tr>
              <tr>
                <td class="title">上架时间：</td>
                <td><input type="text" <?php if($position_id == 9){ echo 'disabled';} ?>  class="input input" name="start_time" id="start_time" value="<?php echo date('Y-m-d', $data->start_time) ?>" maxlength="10"></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'product_img'); ?>：</td>
                <td><input type="text" class="input input-big" name="product_img" id="product_img" value="<?php echo $data->product_img ?>"  placeholder="http://">
                  <div class="trip">*图片规定尺寸大小300*300，图片使用清新背景图，模特浅底图，除品牌logo以外不能有其他字眼，请按要求来，否则不予通过。</div></td>
              </tr>
              <tr>
                <td class="title"></td>
                <td><div class="product_img"> </div></td>
              </tr>
              <tr>
                <td class="title"><?php echo CHtml::activeLabel($model, 'goods_brief'); ?>：</td>
                <td><textarea name="goods_brief" style=" width:483px; height:100px;" placeholder="商品简介不能少于25个字"><?php echo $data->goods_brief ?></textarea></td>
              </tr>
              <tr>
                <td class="title"></td>
                <td><input type="hidden" name="goods_id" value="<?php echo $data->goods_id ?>" />
                  <input class="bm-btn bm-spt" type="submit" value=""></td>
              </tr>
            </tbody>
          </table>
        </form>
        <div class="bottom"> 已经有报名的商品，<a href="<?php echo YzwController::U('goods') ?>">点击查询报名情况</a>! </div>
      </div>
    </div>
  </div>
  <?php include $this->getViewFile('statement'); ?>
  <div class="clear"></div>
</div>
<?php include $this->getViewFile('container'); ?>
<script src="<?php echo Yii::app()->params->staticUrl; ?>statics/js/ajaxForm.js"></script>
<link rel="stylesheet" href="<?php echo Yii::app()->params->staticUrl; ?>statics/js/artDialog6/css/ui-dialog.css">
<script src="<?php echo Yii::app()->params->staticUrl; ?>statics/js/artDialog6/js/dialog-min.js"></script>  
<script>
var tips = dialog();
function product_img() {
    $('div.product_img img').click(function() {
        $('div.product_img img').removeClass('current');
        $(this).addClass('current');
        $('#product_img').val(this.src);
    });
}

function getInfo() {
    var product_id = $('input[name="detail_url"]').val();
    if (product_id == '') {
        return false;
    }
	tips = dialog({
        fixed: true,
        title: '获取商品信息中...'
    }).show();
    $.getJSON('<?php echo YzwController::U('bm/iteminfo') ?>', {product_id: product_id}, function(data) {
		tips.close();
            if (data.status) {
                $('#detail_url').val(data.detail_url);
                $('#goods_name').val(data.title);
                //原价
                $('#p_price').val(data.p_price);
                $('input[name="p_price"]').val(data.p_price);
                //活动价格
                $('#promo_price').val(data.promo_price);
                //商品ID
                $('#product_id').val(data.product_id);
                $('input[name="product_id"]').val(data.product_id);
                //旺旺
                $('input[name="nick"]').val(data.nick);
                //店铺类型
                $('input[name="item_type"]').val(data.item_type);
                //销量
                $('#sales').val(data.sales);
                //店铺等级
                $('#credit_score').val(data.credit_score);
                //图片
                var imgstr = '';
                if (data.images) {
                    $.each(data.images, function(i, v) {
                        if (i == 0) {
                            $('#product_img').val(v);
                            imgstr += '<img class="current" width="160" height="160" src=' + v + ' />';
                        } else {
                            imgstr += '<img  width="160" height="160"  src=' + v + ' />';
                        }
                    });
                    $('div.product_img').html(imgstr);
                    product_img();
                }
            }
        });
}
$(function() {
    $('#goodsbm').ajaxForm({
        dataType: 'json',
		beforeSubmit: function(data, obj, es) {
            tips = dialog({
                fixed: true,
                title: '提交中...',
                cancelDisplay: false
            }).showModal();
            return true;
        },
        success: function(data) {
            tips.title('系统提示');
			tips.content(data.info);
			tips.button([{
				value: '确定',
				callback: function () {
					 if (data.status) {
                        $('#goodsbm').clearForm();
                        $('div.product_img').html('');
                        if (data.url) {
                            window.location.href = data.url;
                        }
                    }
					return true;
				},
				autofocus: true
			}]);
			tips.addEventListener('close',function(){
				if (data.url) {
					window.location.href = data.url;
				}
			});
        }
    });
    $('#get_good').click(function() {
        //getInfo();
    });
    $('input[name="detail_url"]').change(function() {
        getInfo();
    });
});
</script>